{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "      <th>name</th>\n",
       "      <th>gender</th>\n",
       "      <th>count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1880</td>\n",
       "      <td>Mary</td>\n",
       "      <td>F</td>\n",
       "      <td>7065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>1880</td>\n",
       "      <td>Anna</td>\n",
       "      <td>F</td>\n",
       "      <td>2604</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1880</td>\n",
       "      <td>Emma</td>\n",
       "      <td>F</td>\n",
       "      <td>2003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>1880</td>\n",
       "      <td>Elizabeth</td>\n",
       "      <td>F</td>\n",
       "      <td>1939</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1880</td>\n",
       "      <td>Minnie</td>\n",
       "      <td>F</td>\n",
       "      <td>1746</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   year       name gender  count\n",
       "0  1880       Mary      F   7065\n",
       "1  1880       Anna      F   2604\n",
       "2  1880       Emma      F   2003\n",
       "3  1880  Elizabeth      F   1939\n",
       "4  1880     Minnie      F   1746"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "#读入数据\n",
    "data = pd.read_csv('data.csv')\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "year       int64\n",
      "name      object\n",
      "gender    object\n",
      "count      int64\n",
      "dtype: object\n",
      "\n",
      "(1957046, 4)\n"
     ]
    }
   ],
   "source": [
    "#查看各列数据类型、数据框行列数\n",
    "print(data.dtypes)\n",
    "print()\n",
    "print(data.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 二、非聚合类方法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.1 map()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 字典映射"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0          女性\n",
       "1          女性\n",
       "2          女性\n",
       "3          女性\n",
       "4          女性\n",
       "           ..\n",
       "1957041    男性\n",
       "1957042    男性\n",
       "1957043    男性\n",
       "1957044    男性\n",
       "1957045    男性\n",
       "Name: gender, Length: 1957046, dtype: object"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#定义F->女性，M->男性的映射字典\n",
    "gender2xb = {'F': '女性', 'M': '男性'}\n",
    "#利用map()方法得到对应gender列的映射列\n",
    "data.gender.map(gender2xb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* lambda函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0          女性\n",
       "1          女性\n",
       "2          女性\n",
       "3          女性\n",
       "4          女性\n",
       "           ..\n",
       "1957041    男性\n",
       "1957042    男性\n",
       "1957043    男性\n",
       "1957044    男性\n",
       "1957045    男性\n",
       "Name: gender, Length: 1957046, dtype: object"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#因为已经知道数据gender列性别中只有F和M所以编写如下lambda函数\n",
    "data.gender.map(lambda x:'女性' if x is 'F' else '男性')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 常规函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0          女性\n",
       "1          女性\n",
       "2          女性\n",
       "3          女性\n",
       "4          女性\n",
       "           ..\n",
       "1957041    男性\n",
       "1957042    男性\n",
       "1957043    男性\n",
       "1957044    男性\n",
       "1957045    男性\n",
       "Name: gender, Length: 1957046, dtype: object"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def gender_to_xb(x):\n",
    "\n",
    "    return '女性' if x is 'F' else '男性'\n",
    "\n",
    "data.gender.map(gender_to_xb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 特殊对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0          This kid's gender is F\n",
       "1          This kid's gender is F\n",
       "2          This kid's gender is F\n",
       "3          This kid's gender is F\n",
       "4          This kid's gender is F\n",
       "                    ...          \n",
       "1957041    This kid's gender is M\n",
       "1957042    This kid's gender is M\n",
       "1957043    This kid's gender is M\n",
       "1957044    This kid's gender is M\n",
       "1957045    This kid's gender is M\n",
       "Name: gender, Length: 1957046, dtype: object"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.gender.map(\"This kid's gender is {}\".format)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.2 apply()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 单列数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0          女性\n",
       "1          女性\n",
       "2          女性\n",
       "3          女性\n",
       "4          女性\n",
       "           ..\n",
       "1957041    男性\n",
       "1957042    男性\n",
       "1957043    男性\n",
       "1957044    男性\n",
       "1957045    男性\n",
       "Name: gender, Length: 1957046, dtype: object"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.gender.apply(lambda x:'女性' if x is 'F' else '男性')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 输入多列数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0               在1880年，叫做Mary性别为女性的新生儿有7065个。\n",
       "1               在1880年，叫做Anna性别为女性的新生儿有2604个。\n",
       "2               在1880年，叫做Emma性别为女性的新生儿有2003个。\n",
       "3          在1880年，叫做Elizabeth性别为女性的新生儿有1939个。\n",
       "4             在1880年，叫做Minnie性别为女性的新生儿有1746个。\n",
       "                          ...                \n",
       "1957041           在2018年，叫做Zylas性别为男性的新生儿有5个。\n",
       "1957042           在2018年，叫做Zyran性别为男性的新生儿有5个。\n",
       "1957043           在2018年，叫做Zyrie性别为男性的新生儿有5个。\n",
       "1957044           在2018年，叫做Zyron性别为男性的新生儿有5个。\n",
       "1957045           在2018年，叫做Zzyzx性别为男性的新生儿有5个。\n",
       "Length: 1957046, dtype: object"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def generate_descriptive_statement(year, name, gender, count):\n",
    "    year, count = str(year), str(count)\n",
    "    gender = '女性' if gender is 'F' else '男性'\n",
    "    \n",
    "    return '在{}年，叫做{}性别为{}的新生儿有{}个。'.format(year, name, gender, count)\n",
    "\n",
    "data.apply(lambda row:generate_descriptive_statement(row['year'],\n",
    "                                                      row['name'],\n",
    "                                                      row['gender'],\n",
    "                                                      row['count']),\n",
    "           axis = 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 输出多列数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0               (M, ary)\n",
       "1               (A, nna)\n",
       "2               (E, mma)\n",
       "3          (E, lizabeth)\n",
       "4             (M, innie)\n",
       "               ...      \n",
       "1957041        (Z, ylas)\n",
       "1957042        (Z, yran)\n",
       "1957043        (Z, yrie)\n",
       "1957044        (Z, yron)\n",
       "1957045        (Z, zyzx)\n",
       "Length: 1957046, dtype: object"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.apply(lambda row: (row['name'][0], row['name'][1:]), axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('M', 'A', 'E', 'E', 'M', 'M', 'I', 'A', 'B', 'S')\n",
      "('ary', 'nna', 'mma', 'lizabeth', 'innie', 'argaret', 'da', 'lice', 'ertha', 'arah')\n"
     ]
    }
   ],
   "source": [
    "a, b = zip(*data.apply(lambda row: (row['name'][0], row['name'][1:]), axis=1))\n",
    "print(a[:10])\n",
    "print(b[:10])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 结合tqdm给apply()过程添加进度条"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "apply: 100%|██████████████████████████████████████████| 1957046/1957046 [01:07<00:00, 28995.42it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0               在1880年，叫做Mary性别为女性的新生儿有7065个。\n",
       "1               在1880年，叫做Anna性别为女性的新生儿有2604个。\n",
       "2               在1880年，叫做Emma性别为女性的新生儿有2003个。\n",
       "3          在1880年，叫做Elizabeth性别为女性的新生儿有1939个。\n",
       "4             在1880年，叫做Minnie性别为女性的新生儿有1746个。\n",
       "                          ...                \n",
       "1957041           在2018年，叫做Zylas性别为男性的新生儿有5个。\n",
       "1957042           在2018年，叫做Zyran性别为男性的新生儿有5个。\n",
       "1957043           在2018年，叫做Zyrie性别为男性的新生儿有5个。\n",
       "1957044           在2018年，叫做Zyron性别为男性的新生儿有5个。\n",
       "1957045           在2018年，叫做Zzyzx性别为男性的新生儿有5个。\n",
       "Length: 1957046, dtype: object"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from tqdm import tqdm\n",
    "\n",
    "def generate_descriptive_statement(year, name, gender, count):\n",
    "    year, count = str(year), str(count)\n",
    "    gender = '女性' if gender is 'F' else '男性'\n",
    "    \n",
    "    return '在{}年，叫做{}性别为{}的新生儿有{}个。'.format(year, name, gender, count)\n",
    "\n",
    "#启动对紧跟着的apply过程的监视\n",
    "tqdm.pandas(desc='apply')\n",
    "data.progress_apply(lambda row:generate_descriptive_statement(row['year'],\n",
    "                                                      row['name'],\n",
    "                                                      row['gender'],\n",
    "                                                      row['count']),\n",
    "          axis = 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 结合tqdm_notebook()给apply()过程添加美观进度条"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "17af636c497c4c99bacd37d14d00f11f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, description='apply', max=1957046, style=ProgressStyle(description_width='i…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0               在1880年，叫做Mary性别为女性的新生儿有7065个。\n",
       "1               在1880年，叫做Anna性别为女性的新生儿有2604个。\n",
       "2               在1880年，叫做Emma性别为女性的新生儿有2003个。\n",
       "3          在1880年，叫做Elizabeth性别为女性的新生儿有1939个。\n",
       "4             在1880年，叫做Minnie性别为女性的新生儿有1746个。\n",
       "                          ...                \n",
       "1957041           在2018年，叫做Zylas性别为男性的新生儿有5个。\n",
       "1957042           在2018年，叫做Zyran性别为男性的新生儿有5个。\n",
       "1957043           在2018年，叫做Zyrie性别为男性的新生儿有5个。\n",
       "1957044           在2018年，叫做Zyron性别为男性的新生儿有5个。\n",
       "1957045           在2018年，叫做Zzyzx性别为男性的新生儿有5个。\n",
       "Length: 1957046, dtype: object"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from tqdm._tqdm_notebook import tqdm_notebook\n",
    "\n",
    "tqdm_notebook.pandas(desc='apply')\n",
    "data.progress_apply(lambda row:generate_descriptive_statement(row['year'],\n",
    "                                                      row['name'],\n",
    "                                                      row['gender'],\n",
    "                                                      row['count']),\n",
    "          axis = 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.3 applymap()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "      <th>name</th>\n",
       "      <th>gender</th>\n",
       "      <th>count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1880</td>\n",
       "      <td>mary</td>\n",
       "      <td>f</td>\n",
       "      <td>7065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>1880</td>\n",
       "      <td>anna</td>\n",
       "      <td>f</td>\n",
       "      <td>2604</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1880</td>\n",
       "      <td>emma</td>\n",
       "      <td>f</td>\n",
       "      <td>2003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>1880</td>\n",
       "      <td>elizabeth</td>\n",
       "      <td>f</td>\n",
       "      <td>1939</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1880</td>\n",
       "      <td>minnie</td>\n",
       "      <td>f</td>\n",
       "      <td>1746</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1957041</td>\n",
       "      <td>2018</td>\n",
       "      <td>zylas</td>\n",
       "      <td>m</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1957042</td>\n",
       "      <td>2018</td>\n",
       "      <td>zyran</td>\n",
       "      <td>m</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1957043</td>\n",
       "      <td>2018</td>\n",
       "      <td>zyrie</td>\n",
       "      <td>m</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1957044</td>\n",
       "      <td>2018</td>\n",
       "      <td>zyron</td>\n",
       "      <td>m</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1957045</td>\n",
       "      <td>2018</td>\n",
       "      <td>zzyzx</td>\n",
       "      <td>m</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1957046 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         year       name gender  count\n",
       "0        1880       mary      f   7065\n",
       "1        1880       anna      f   2604\n",
       "2        1880       emma      f   2003\n",
       "3        1880  elizabeth      f   1939\n",
       "4        1880     minnie      f   1746\n",
       "...       ...        ...    ...    ...\n",
       "1957041  2018      zylas      m      5\n",
       "1957042  2018      zyran      m      5\n",
       "1957043  2018      zyrie      m      5\n",
       "1957044  2018      zyron      m      5\n",
       "1957045  2018      zzyzx      m      5\n",
       "\n",
       "[1957046 rows x 4 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def lower_all_string(x):\n",
    "    if isinstance(x, str):\n",
    "        return x.lower()\n",
    "    else:\n",
    "        return x\n",
    "\n",
    "data.applymap(lower_all_string)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.applymap(lower_all_string).shape == data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 三、聚合类方法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.1 利用groupby()进行分组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.groupby.generic.DataFrameGroupBy"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#按照年份和性别对婴儿姓名数据进行分组\n",
    "groups = data.groupby(by=['year','gender'])\n",
    "#查看groups类型\n",
    "type(groups)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((1880, 'F'),      year       name gender  count\n",
       " 0    1880       Mary      F   7065\n",
       " 1    1880       Anna      F   2604\n",
       " 2    1880       Emma      F   2003\n",
       " 3    1880  Elizabeth      F   1939\n",
       " 4    1880     Minnie      F   1746\n",
       " ..    ...        ...    ...    ...\n",
       " 937  1880        Ula      F      5\n",
       " 938  1880     Vannie      F      5\n",
       " 939  1880     Verona      F      5\n",
       " 940  1880     Vertie      F      5\n",
       " 941  1880      Wilma      F      5\n",
       " \n",
       " [942 rows x 4 columns])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#利用列表解析提取分组结果\n",
    "groups = [group for group in groups]\n",
    "groups[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 直接调用聚合函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "year  gender\n",
       "1880  F          7065\n",
       "      M          9655\n",
       "1881  F          6919\n",
       "      M          8769\n",
       "1882  F          8148\n",
       "                ...  \n",
       "2016  M         19117\n",
       "2017  F         19800\n",
       "      M         18798\n",
       "2018  F         18688\n",
       "      M         19837\n",
       "Name: count, Length: 278, dtype: int64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求每个分组中最高频次\n",
    "data.groupby(by=['year','gender'])['count'].max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "      <th>gender</th>\n",
       "      <th>count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1880</td>\n",
       "      <td>F</td>\n",
       "      <td>7065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>1880</td>\n",
       "      <td>M</td>\n",
       "      <td>9655</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1881</td>\n",
       "      <td>F</td>\n",
       "      <td>6919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>1881</td>\n",
       "      <td>M</td>\n",
       "      <td>8769</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1882</td>\n",
       "      <td>F</td>\n",
       "      <td>8148</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>273</td>\n",
       "      <td>2016</td>\n",
       "      <td>M</td>\n",
       "      <td>19117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>274</td>\n",
       "      <td>2017</td>\n",
       "      <td>F</td>\n",
       "      <td>19800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>275</td>\n",
       "      <td>2017</td>\n",
       "      <td>M</td>\n",
       "      <td>18798</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>276</td>\n",
       "      <td>2018</td>\n",
       "      <td>F</td>\n",
       "      <td>18688</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>277</td>\n",
       "      <td>2018</td>\n",
       "      <td>M</td>\n",
       "      <td>19837</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>278 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     year gender  count\n",
       "0    1880      F   7065\n",
       "1    1880      M   9655\n",
       "2    1881      F   6919\n",
       "3    1881      M   8769\n",
       "4    1882      F   8148\n",
       "..    ...    ...    ...\n",
       "273  2016      M  19117\n",
       "274  2017      F  19800\n",
       "275  2017      M  18798\n",
       "276  2018      F  18688\n",
       "277  2018      M  19837\n",
       "\n",
       "[278 rows x 3 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#使用reset_index(drop=False)还原数据框\n",
    "data.groupby(by=['year','gender'])['count'].max().reset_index(drop=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 结合apply()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\programdata\\anaconda3\\lib\\site-packages\\numpy\\core\\fromnumeric.py:61: FutureWarning: \n",
      "The current behaviour of 'Series.argmax' is deprecated, use 'idxmax'\n",
      "instead.\n",
      "The behavior of 'argmax' will be corrected to return the positional\n",
      "maximum in the future. For now, use 'series.values.argmax' or\n",
      "'np.argmax(np.array(values))' to get the position of the maximum\n",
      "row.\n",
      "  return bound(*args, **kwds)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "      <th>gender</th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1880</td>\n",
       "      <td>F</td>\n",
       "      <td>7065-Mary</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>1880</td>\n",
       "      <td>M</td>\n",
       "      <td>9655-John</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1881</td>\n",
       "      <td>F</td>\n",
       "      <td>6919-Mary</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>1881</td>\n",
       "      <td>M</td>\n",
       "      <td>8769-John</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1882</td>\n",
       "      <td>F</td>\n",
       "      <td>8148-Mary</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>273</td>\n",
       "      <td>2016</td>\n",
       "      <td>M</td>\n",
       "      <td>19117-Noah</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>274</td>\n",
       "      <td>2017</td>\n",
       "      <td>F</td>\n",
       "      <td>19800-Emma</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>275</td>\n",
       "      <td>2017</td>\n",
       "      <td>M</td>\n",
       "      <td>18798-Liam</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>276</td>\n",
       "      <td>2018</td>\n",
       "      <td>F</td>\n",
       "      <td>18688-Emma</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>277</td>\n",
       "      <td>2018</td>\n",
       "      <td>M</td>\n",
       "      <td>19837-Liam</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>278 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     year gender           0\n",
       "0    1880      F   7065-Mary\n",
       "1    1880      M   9655-John\n",
       "2    1881      F   6919-Mary\n",
       "3    1881      M   8769-John\n",
       "4    1882      F   8148-Mary\n",
       "..    ...    ...         ...\n",
       "273  2016      M  19117-Noah\n",
       "274  2017      F  19800-Emma\n",
       "275  2017      M  18798-Liam\n",
       "276  2018      F  18688-Emma\n",
       "277  2018      M  19837-Liam\n",
       "\n",
       "[278 rows x 3 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "def find_most_name(df):\n",
    "    return str(np.max(df['count']))+'-'+df['name'][np.argmax(df['count'])]\n",
    "\n",
    "data.groupby(['year','gender']).apply(find_most_name).reset_index(drop=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.2 利用agg()进行更灵活的聚合"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 聚合Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "min           5.0\n",
       "max       99689.0\n",
       "median       12.0\n",
       "Name: count, dtype: float64"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求count列的最小值、最大值以及中位数\n",
    "data['count'].agg(['min','max','median'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 聚合数据框"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "      <th>count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>max</td>\n",
       "      <td>2018.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>mean</td>\n",
       "      <td>NaN</td>\n",
       "      <td>179.685621</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>min</td>\n",
       "      <td>1880.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>std</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1522.803579</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        year        count\n",
       "max   2018.0          NaN\n",
       "mean     NaN   179.685621\n",
       "min   1880.0          NaN\n",
       "std      NaN  1522.803579"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.agg({'year': ['max','min'], 'count': ['mean','std']})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 聚合groupby()结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "      <th>gender</th>\n",
       "      <th colspan=\"3\" halign=\"left\">count</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>min</th>\n",
       "      <th>max</th>\n",
       "      <th>median</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1880</td>\n",
       "      <td>F</td>\n",
       "      <td>5</td>\n",
       "      <td>7065</td>\n",
       "      <td>13.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>1880</td>\n",
       "      <td>M</td>\n",
       "      <td>5</td>\n",
       "      <td>9655</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1881</td>\n",
       "      <td>F</td>\n",
       "      <td>5</td>\n",
       "      <td>6919</td>\n",
       "      <td>13.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>1881</td>\n",
       "      <td>M</td>\n",
       "      <td>5</td>\n",
       "      <td>8769</td>\n",
       "      <td>13.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1882</td>\n",
       "      <td>F</td>\n",
       "      <td>5</td>\n",
       "      <td>8148</td>\n",
       "      <td>13.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>273</td>\n",
       "      <td>2016</td>\n",
       "      <td>M</td>\n",
       "      <td>5</td>\n",
       "      <td>19117</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>274</td>\n",
       "      <td>2017</td>\n",
       "      <td>F</td>\n",
       "      <td>5</td>\n",
       "      <td>19800</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>275</td>\n",
       "      <td>2017</td>\n",
       "      <td>M</td>\n",
       "      <td>5</td>\n",
       "      <td>18798</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>276</td>\n",
       "      <td>2018</td>\n",
       "      <td>F</td>\n",
       "      <td>5</td>\n",
       "      <td>18688</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>277</td>\n",
       "      <td>2018</td>\n",
       "      <td>M</td>\n",
       "      <td>5</td>\n",
       "      <td>19837</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>278 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     year gender count              \n",
       "                   min    max median\n",
       "0    1880      F     5   7065   13.0\n",
       "1    1880      M     5   9655   12.0\n",
       "2    1881      F     5   6919   13.5\n",
       "3    1881      M     5   8769   13.0\n",
       "4    1882      F     5   8148   13.0\n",
       "..    ...    ...   ...    ...    ...\n",
       "273  2016      M     5  19117   12.0\n",
       "274  2017      F     5  19800   12.0\n",
       "275  2017      M     5  18798   11.0\n",
       "276  2018      F     5  18688   12.0\n",
       "277  2018      M     5  19837   12.0\n",
       "\n",
       "[278 rows x 5 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.groupby(['year','gender']).agg({'count':['min','max','median']}).reset_index(drop=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "      <th>gender</th>\n",
       "      <th>min_count</th>\n",
       "      <th>max_count</th>\n",
       "      <th>median</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1880</td>\n",
       "      <td>F</td>\n",
       "      <td>5</td>\n",
       "      <td>7065</td>\n",
       "      <td>13.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>1880</td>\n",
       "      <td>M</td>\n",
       "      <td>5</td>\n",
       "      <td>9655</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1881</td>\n",
       "      <td>F</td>\n",
       "      <td>5</td>\n",
       "      <td>6919</td>\n",
       "      <td>13.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>1881</td>\n",
       "      <td>M</td>\n",
       "      <td>5</td>\n",
       "      <td>8769</td>\n",
       "      <td>13.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1882</td>\n",
       "      <td>F</td>\n",
       "      <td>5</td>\n",
       "      <td>8148</td>\n",
       "      <td>13.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>273</td>\n",
       "      <td>2016</td>\n",
       "      <td>M</td>\n",
       "      <td>5</td>\n",
       "      <td>19117</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>274</td>\n",
       "      <td>2017</td>\n",
       "      <td>F</td>\n",
       "      <td>5</td>\n",
       "      <td>19800</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>275</td>\n",
       "      <td>2017</td>\n",
       "      <td>M</td>\n",
       "      <td>5</td>\n",
       "      <td>18798</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>276</td>\n",
       "      <td>2018</td>\n",
       "      <td>F</td>\n",
       "      <td>5</td>\n",
       "      <td>18688</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>277</td>\n",
       "      <td>2018</td>\n",
       "      <td>M</td>\n",
       "      <td>5</td>\n",
       "      <td>19837</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>278 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     year gender  min_count  max_count  median\n",
       "0    1880      F          5       7065    13.0\n",
       "1    1880      M          5       9655    12.0\n",
       "2    1881      F          5       6919    13.5\n",
       "3    1881      M          5       8769    13.0\n",
       "4    1882      F          5       8148    13.0\n",
       "..    ...    ...        ...        ...     ...\n",
       "273  2016      M          5      19117    12.0\n",
       "274  2017      F          5      19800    12.0\n",
       "275  2017      M          5      18798    11.0\n",
       "276  2018      F          5      18688    12.0\n",
       "277  2018      M          5      19837    12.0\n",
       "\n",
       "[278 rows x 5 columns]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.groupby(['year','gender']).agg(\n",
    "    min_count=pd.NamedAgg(column='count', aggfunc='min'),\n",
    "    max_count=pd.NamedAgg(column='count', aggfunc='max'),\n",
    "    median=pd.NamedAgg(column='count', aggfunc='median')).reset_index(drop=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {
     "10c9323d4d294156b55e746abbfd5ef0": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "IntProgressModel",
      "state": {
       "bar_style": "success",
       "description": "apply",
       "layout": "IPY_MODEL_4466c71b44254fbbbd98cea0338a27f3",
       "max": 1957046,
       "style": "IPY_MODEL_b0634eeb1b0344709548d27da508d073",
       "value": 1957046
      }
     },
     "17af636c497c4c99bacd37d14d00f11f": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "HBoxModel",
      "state": {
       "children": [
        "IPY_MODEL_10c9323d4d294156b55e746abbfd5ef0",
        "IPY_MODEL_282a66465b564754978c09d2684be08f"
       ],
       "layout": "IPY_MODEL_f95291a0bbc54013b3047867f0f96cba"
      }
     },
     "282a66465b564754978c09d2684be08f": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "HTMLModel",
      "state": {
       "layout": "IPY_MODEL_562bbde9dfa94cd1ac05a199baa25d6a",
       "style": "IPY_MODEL_6fe79b1413ed428ab39352b04ec7b327",
       "value": "100% 1957046/1957046 [01:12&lt;00:00, 26872.53it/s]"
      }
     },
     "4466c71b44254fbbbd98cea0338a27f3": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {}
     },
     "562bbde9dfa94cd1ac05a199baa25d6a": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {}
     },
     "6fe79b1413ed428ab39352b04ec7b327": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "DescriptionStyleModel",
      "state": {
       "description_width": ""
      }
     },
     "b0634eeb1b0344709548d27da508d073": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "ProgressStyleModel",
      "state": {
       "description_width": "initial"
      }
     },
     "f95291a0bbc54013b3047867f0f96cba": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {}
     }
    },
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
